

using UnityEngine;


/// <summary>
/// RoleEntity显示层处理
/// </summary>
public partial class RoleEntity
{
    [SerializeField]
    protected ZRoleAnim m_rc;
    public virtual ZRoleAnim roleAnim 
    {
        get 
        {
            return m_rc;
        }
    }
    protected Rigidbody m_Rigidbody;
    public Rigidbody Rigidbody => m_Rigidbody;

    public Animator Animator => roleAnim.animator;

    [SerializeField]
    protected RagdollCtrl m_RagdollCtrl;
    public RagdollCtrl ragdollCtrl => m_RagdollCtrl;

    public void ShowNormalGo()
    {
        if (m_RagdollCtrl)
        {
            m_RagdollCtrl.ShowNormal();
        }
    }

    public void ShowDieGo()
    {
        if (m_RagdollCtrl)
        {
            m_RagdollCtrl.ShowRagdoll();
        }
    }


    /// <summary>
    /// rotate to focus to target pos
    /// </summary>
    /// <param name="pos"></param>
    /// <param name="lerp"></param>
    public void FocusTo(Vector3 pos, bool lerp = false)
    {
        var vec = pos - transform.position;

        Vector2 dir2D = new Vector2(vec.x, vec.z);

        if (dir2D.sqrMagnitude > 0)
        {
            if (lerp)
            {
                Quaternion targetRotation = Quaternion.Euler(0, DirToRotateAngle(dir2D), 0);
                this.transform.rotation = Quaternion.Lerp(this.transform.rotation, targetRotation,
                    Time.deltaTime * c_rotateSpeed);
            }
            else
            {
                Quaternion targetRotation = Quaternion.Euler(0, DirToRotateAngle(dir2D), 0);
                this.transform.rotation = targetRotation;
            }
        }
    }
    protected virtual void ViewUpdate()
    {
        //if(rc)
        //    rc.transform.localPosition = Vector3.zero;
    }

}